package com.xc.h05.controller.weichen;

import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Question;
import com.xc.h05.service.weichen.QuestionService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/question")
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    @PostMapping("/add")
    public R add(Question question){
        int add = questionService.add(question);
        if (add!=0){
            return R.ok(question);
        }else {
            return R.fail("添加失败");
        }
    }
    @PostMapping("/add2")
    public R add2(@RequestBody Question question){
        int add = questionService.add(question);
        if (add!=0){
            return R.ok(question);
        }else {
            return R.fail("添加失败");
        }
    }
    @PutMapping("/update")
    public R update(@RequestBody Question question){
        int update = questionService.update(question);
        if (update!=0){
            return R.ok(question);
        }else {
            return R.fail("修改失败");
        }
    }
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable(value = "id") int id){
        int delete = questionService.delete(id);
        if (delete!=0){
            return R.ok(delete);
        }else {
            return R.fail("修改失败");
        }
    }

    @PostMapping("/deletes")
    public R deletes(@RequestBody List<Integer> list){
        int deletes = questionService.deletes(list);
        if (deletes!=0){
            return R.ok(deletes);
        }else {
            return R.fail("修改失败");
        }
    }

    @GetMapping("findByPage")
    public R findByPage(int pageNum,int pageSize,Question question){
        PageInfo<Question> pageInfo = questionService.findByPage(pageNum, pageSize, question);
        return R.ok(pageInfo);
    }
    @GetMapping("/findById")
    public R findById(int id){
        Question question = questionService.findById(id);
        return R.ok(question);
    }
    @GetMapping("/findAll")
    public R findAll(){
        List<Question> list = questionService.findAll();
        return R.ok(list);
    }

}
